package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.qo.qsdk.model.UserModel;
import com.qo.qsdk.ui.QSDKListener;
import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;
import com.qo.qsdk.utils.QSDKHelper;

public class LoadingView implements IBaseView{

    private QTextView mTitle, mAccount, mChange;
    private QBTextView mBtn;
    private View mMain;
    private Activity mActivity;
    private QSDKListener mQSDKListener;

    public LoadingView(Activity mActivity, QSDKListener iAccountListener) {
        this.mActivity = mActivity;
        this.mQSDKListener = iAccountListener;
        init(mActivity);
    }

    private void init(Activity v) {
        mMain = v.findViewById(DynamicUtils.id(mActivity, "mainLoading"));
        mMain.setVisibility(View.GONE);
        mTitle = v.findViewById(DynamicUtils.id(mActivity, "loadingTitle"));
        mAccount = v.findViewById(DynamicUtils.id(mActivity, "loadingAccount"));
        mChange = v.findViewById(DynamicUtils.id(mActivity, "loadingChange"));
        mBtn = v.findViewById(DynamicUtils.id(mActivity, "loadingBtn"));
        mMain.setVisibility(View.GONE);

        mChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onLoadingChange();
            }
        });

        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onLoadingContinue();
            }
        });
    }

    public void show(Activity activity) {
        refresh();
        mMain.setVisibility(View.VISIBLE);
    }

    public void hide(Activity activity) {
        mMain.setVisibility(View.GONE);
    }

    public void refresh() {
        UserModel userModel = QSDKHelper.getInstance().getUserInfoModel(this.mActivity);
        mTitle.setText(Language.Loading_Title.toString());
        mAccount.setText(userModel.getAccount());
        mChange.setText(userModel.isGuest() ? Language.Loading_Bind.toString() : Language.Loading_Change.toString());
        mBtn.setText(Language.Loading_Btn.toString());
    }
}
